package com.star.learn.excel.component;

import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;

@Component
public class ConfirmHolder {

    // 将 static 移除，由 Spring 管理实例
    private final Map<String, CompletableFuture<Boolean>> futureMap = new ConcurrentHashMap<>();

    public void register(String id, CompletableFuture<Boolean> future) {
        futureMap.put(id, future);
    }

    public void notifyConfirm(String id, boolean ack) {
        CompletableFuture<Boolean> future = futureMap.remove(id);
        if (future != null) {
            future.complete(ack);
        }
    }
}
